package gwtappcontainer.server;


import gwtappcontainer.client.LoginService;
import gwtappcontainer.shared.LoginInfoProp;

import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;

@SuppressWarnings("serial")
public class LoginServiceImpl extends RemoteServiceServlet implements
    LoginService {

  public LoginInfoProp login(String requestUri) {
    UserService userService = UserServiceFactory.getUserService();
    User user = userService.getCurrentUser();
    LoginInfoProp loginInfo = new LoginInfoProp();

    if (user != null) {
    	loginInfo.loggedIn = true;
    	loginInfo.emailAddress = user.getEmail();
    	loginInfo.nickname = user.getNickname();
    	loginInfo.logoutUrl = userService.createLogoutURL(requestUri);      
    } else {
    	loginInfo.loggedIn = false; 
    	loginInfo.loginUrl = userService.createLoginURL(requestUri);
    }
    
    return loginInfo;
  }
}